package gui.wizard;

import generated.business.avatar.AvatarServicePackage.Gender;
import generated.business.avatar.AvatarServicePackage.Mood;
import generated.business.avatar.AvatarServicePackage.Size;

import org.eclipse.jface.wizard.WizardPage;
import org.eclipse.swt.SWT;
import org.eclipse.swt.custom.CCombo;
import org.eclipse.swt.custom.CLabel;
import org.eclipse.swt.events.ModifyEvent;
import org.eclipse.swt.events.ModifyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Text;

import vworld.adapter.GenderAdapter;
import vworld.adapter.MoodAdapter;
import vworld.adapter.SizeAdapter;

class CreationAvatarPage extends WizardPage {

	private Text nameText;
	private CCombo genderCombo;
	private CCombo moodCombo;
	private CCombo sizeCombo;

	public CreationAvatarPage() {
		super("CreationAvatarPage");
		setTitle("Avatar creation");
		setMessage("Create your awesome personal avatar");
		setPageComplete(false);
	}

	/**
	 * Creates the controls for this page
	 */
	public void createControl(Composite parent) {
		Composite composite = new Composite(parent, SWT.NONE);
		composite.setLayout(new GridLayout(3, false));

		GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
		gridData.grabExcessHorizontalSpace = true;

		CLabel nameLabel = new CLabel(composite, SWT.NONE);
		nameLabel.setText("Name*");
		nameText = new Text(composite, SWT.NONE);
		nameText.setLayoutData(gridData);
		nameText.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				setPageComplete(isComplete());
			}
		});
		new CLabel(composite, SWT.NULL);

		CLabel genderLabel = new CLabel(composite, SWT.NONE);
		genderLabel.setText("Gender*");
		genderCombo = new CCombo(composite, SWT.NONE | SWT.SIMPLE
				| SWT.READ_ONLY);
		genderCombo.add(GenderAdapter.toString(Gender.male));
		genderCombo.add(GenderAdapter.toString(Gender.female));
		genderCombo.setLayoutData(gridData);
		genderCombo.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				setPageComplete(isComplete());
			}
		});

		new CLabel(composite, SWT.NULL);

		CLabel moodLabel = new CLabel(composite, SWT.NONE);
		moodLabel.setText("Mood*");
		moodCombo = new CCombo(composite, SWT.NONE | SWT.SIMPLE | SWT.READ_ONLY);
		moodCombo.add(MoodAdapter.toString(Mood.happy));
		moodCombo.add(MoodAdapter.toString(Mood.laughing));
		moodCombo.add(MoodAdapter.toString(Mood.sad));
		moodCombo.add(MoodAdapter.toString(Mood.scared));
		moodCombo.add(MoodAdapter.toString(Mood.worried));
		moodCombo.setLayoutData(gridData);
		moodCombo.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				setPageComplete(isComplete());
			}
		});
		new CLabel(composite, SWT.NULL);

		CLabel sizeLabel = new CLabel(composite, SWT.NONE);
		sizeLabel.setText("Size*");
		sizeCombo = new CCombo(composite, SWT.NONE | SWT.SIMPLE | SWT.READ_ONLY);
		sizeCombo.add(SizeAdapter.toString(Size.average));
		sizeCombo.add(SizeAdapter.toString(Size.dwarf));
		sizeCombo.add(SizeAdapter.toString(Size.giant));
		sizeCombo.add(SizeAdapter.toString(Size.small));
		sizeCombo.add(SizeAdapter.toString(Size.tall));
		sizeCombo.setLayoutData(gridData);
		sizeCombo.addModifyListener(new ModifyListener() {
			public void modifyText(ModifyEvent e) {
				setPageComplete(isComplete());
			}
		});

		setControl(composite);
		nameText.setFocus();
		composite.setSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
	}

	public boolean isComplete() {
		if (!nameText.getText().equals("") && !genderCombo.getText().equals("")
				&& !moodCombo.getText().equals("")
				&& !sizeCombo.getText().equals("")) {
			return true;
		}
		return false;
	}

	/**
	 * @return the nameText
	 */
	public Text getNameText() {
		return nameText;
	}

	/**
	 * @param nameText
	 *            the nameText to set
	 */
	public void setNameText(Text nameText) {
		this.nameText = nameText;
	}

	/**
	 * @return the genderCombo
	 */
	public CCombo getGenderCombo() {
		return genderCombo;
	}

	/**
	 * @param genderCombo
	 *            the genderCombo to set
	 */
	public void setGenderCombo(CCombo genderCombo) {
		this.genderCombo = genderCombo;
	}

	/**
	 * @return the moodCombo
	 */
	public CCombo getMoodCombo() {
		return moodCombo;
	}

	/**
	 * @param moodCombo
	 *            the moodCombo to set
	 */
	public void setMoodCombo(CCombo moodCombo) {
		this.moodCombo = moodCombo;
	}

	/**
	 * @return the sizeCombo
	 */
	public CCombo getSizeCombo() {
		return sizeCombo;
	}

	/**
	 * @param sizeCombo
	 *            the sizeCombo to set
	 */
	public void setSizeCombo(CCombo sizeCombo) {
		this.sizeCombo = sizeCombo;
	}
}